package cn.com.yinhex.service.impl;

import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import cn.com.yinhex.dao.UserDao;
import cn.com.yinhex.domain.User;
import cn.com.yinhex.service.UserService;
import cn.com.yinhex.util.Pager;
@Service("userService")
public class UserServiceImpl implements UserService{
	private static final Logger logger = Logger.getLogger(UserServiceImpl.class);
	@Resource(name="userDao")
    private UserDao userDao;
    
	public User login(String email, String password) {
		User user = null;
		try {
			user = userDao.login(email, password);
		} catch (Exception e) {
			System.out.println("login出错了");
			e.printStackTrace();
		}
		return user;
		
		
	}

	public void addUser(User user) {
		String uuid = UUID.randomUUID().toString().replaceAll("-", "");
		user.setUserId(uuid);
		user.setStatus(1);//默认用户为激活状态
		user.setAllStr(user.toString());
		
		try {
			userDao.insert(user);
		} catch (Exception e) {
			logger.info("增加一个用户出错addUser");
			e.printStackTrace();
		}
		
	}

	public List<User> getUserList(String qq,Pager pager) {
		List<User> userList = null;
		try {
				userList = userDao.getUserList(qq, pager);
		} catch (Exception e) {
			logger.info("Dao===getUserList=======出错了");
			e.printStackTrace();
		}
		return userList;
	}

	public void deleteUser(String userid) {
		try {
			userDao.delete(userid);
		} catch (Exception e) {
			logger.info("删除用户出错啦=======");
			e.printStackTrace();
		}
		
	}

	public void updateUser(User user) {
		// TODO Auto-generated method stub
		
	}

	public User getUserById(String userId) {
		User  user = null;
		try {
			user  = userDao.getUserById(userId);
		} catch (Exception e) {
			logger.info("getUserById=========");
			e.printStackTrace();
		}
		return user;
	}

}
